﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class WeaponDescriptionPanel : MonoBehaviour
{
    public Image m_Perview;
    public Text m_Name2;
    public Text m_ShotRange;
    public Text m_TurnSpeed;
    public Text m_FlyVelocity;
    public Text m_ShotSpeed;
    public Text m_Damage;
    public Text m_DPSL;
    public Text m_ShotError;
    public Text m_DescriptionL;

    public Image m_LevelBig;
    public Image m_LevelMiddle;
    public Image m_LevelSmall;
    public Image m_LevelEnergy;
    public Image m_LevelExplosion;
    public Image m_LevelK;

    public Weapon PerviewWeapon
    {
        set { 
            m_Weapon = value;
            m_LevelBig      .gameObject.SetActive(false);
            m_LevelMiddle   .gameObject.SetActive(false);
            m_LevelSmall    .gameObject.SetActive(false);
            m_LevelEnergy   .gameObject.SetActive(false);
            m_LevelExplosion.gameObject.SetActive(false);
            m_LevelK        .gameObject.SetActive(false);
            if (m_Weapon == null)
            {
                m_Perview.sprite = Resources.Load<Sprite>("Textures/Null");
                m_Name2.text = "null";
                m_ShotRange.text = "null";
                m_ShotSpeed.text = "null";
                m_Damage.text = "null";
                m_DPSL.text = "null";
                m_ShotError.text = "null";
                m_DescriptionL.text = "null";
                m_TurnSpeed.text = "null";
                m_FlyVelocity.text = "null";
            }
            else
            {
                m_Perview.sprite = Resources.Load<Sprite>(m_Weapon.Perview);
                m_Perview.preserveAspect = true;
                m_Name2.text = m_Weapon.Name;
                m_ShotRange.text = ((int)(m_Weapon.ShutRange*100f)).ToString();
                m_ShotSpeed.text = m_Weapon.ShutVelocity.ToString();
                m_Damage.text = m_Weapon.Damage.ToString();
                m_DPSL.text = (m_Weapon.Damage/ m_Weapon.ShutVelocity).ToString("0.00");
                m_ShotError.text = m_Weapon.m_ShotErrorValueMax.ToString();
                m_DescriptionL.text = m_Weapon.Description;
                m_TurnSpeed.text = m_Weapon.TurnSpeed.ToString("F1") + "°/s";
                m_FlyVelocity.text = (m_Weapon.BulletFlyVelocity*100).ToString() + "/s";
                switch(m_Weapon.m_Level)
                {
                    case Weapon.Level.LEVEL_BIG:
                        m_LevelBig.gameObject.SetActive(true);
                        break;
                    case Weapon.Level.LEVEL_MIDDLE:
                        m_LevelMiddle.gameObject.SetActive(true);
                        break;
                    case Weapon.Level.LEVEL_SMALL:
                        m_LevelSmall.gameObject.SetActive(true);
                        break;
                }
                switch (m_Weapon.m_DamageType)
                {
                    case Weapon.DamageType.TYPE_ENERGY:
                        m_LevelEnergy.gameObject.SetActive(true);
                        break;
                    case Weapon.DamageType.TYPE_EXPLOSION:
                        m_LevelExplosion.gameObject.SetActive(true);
                        break;
                    case Weapon.DamageType.TYPE_KINETIC:
                        m_LevelK.gameObject.SetActive(true);
                        break;
                }
            }
        }
        get { return m_Weapon; }
    }

    Weapon m_Weapon;
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}
